package com.gxjc.dao.bean;

import java.util.List;

import org.hibernate.Session;

import com.gxjc.model.Role;

public class RoleDao extends BaseDao {
	public List<Role> getAll() {
		String hql = "FROM Role";
		return getSession().createQuery(hql).list();
	}

	public void save(Role role) {
		Session session = getSession();
		session.save(role);
		session.getTransaction().commit();
		session.close();
	}

	public void update(Role role) {
		Session session = getSession();
		session.update(role);
		session.getTransaction().commit();
		session.close();
	}
	
	public void delete(int id) {
		getSession().delete(getSession().get(Role.class,id));
	}
	
	public Role getRoleById(int id) {
		return (Role)getSession().get(Role.class,id);
	}
	
	public List<Role> getRoleBySql(String hql) {
		return getSession().createQuery(hql).list();
	}
}
